<?php

$respond = 0;
if($id && isset($_POST['cat']) &&
   $FILTER->isValidInteger($_POST['cat']) &&
   isset($_POST['mail']) &&
   $FILTER->isValidEmail($_POST['mail']))
{  
   $body = '<html><head><title>'. $var['send2friend']['subject'] .'</title></head><body>' . $var['send2friend']['mail'] .'</body></html>';
   $body = nl2br($body);
   
   $href = 'http://'. $_SERVER['HTTP_HOST'] . $categories[$_POST['cat']]['url'] . $id . '.html';
   $href = '<a href="'. $href . '">' . $href . '</a>';
   
   $body = str_replace(array('{link}'), array($href), $body);
   
   
   $subject = $var['send2friend']['subject'];
   $subject = mime_header_encode($subject, false);
   
   $headers  = "Content-type: text/html; charset=utf-8 \r\n";
   $headers .= "From: =?utf-8?B?".base64_encode($var['company']['responder'])."?=<" . $var['company']['email'] . ">\r\n";
   $headers .= "X-Mailer: PHPMail Tool\n";
   $headers .= "Reply-To: =?utf-8?B?".base64_encode($var['company']['responder'])."?=<" . $var['company']['email'] . ">\r\n";
   $headers .= "Mime-Version: 1.0\n";
   
   
   if(@mail($_POST['mail'], $subject, $body, $headers))
   {
      $respond = 1;
   }
}

echo $respond;
exit();


function mime_header_encode($string, $split = true) {
  if (preg_match('/[^\x20-\x7E]/', $string)) {
    if (!$split)
      return ' =?UTF-8?B?'. base64_encode($string) ."?=";
    $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
    $len = strlen($string);
    $output = '';
    while ($len > 0) {
      $chunk = truncate_utf8($string, $chunk_size);
      $output .= ' =?UTF-8?B?'. base64_encode($chunk) ."?=\n";
      $c = strlen($chunk);
      $string = substr($string, $c);
      $len -= $c;
    }
    return trim($output);
  }
  return $string;
}